package org.marvell.infra;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.seleniumemulation.DragAndDrop;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class NikolaLoginPage {
	
	@FindBy(id="userName$query")
	WebElement userName;
	
	@FindBy(id="password")
	WebElement password;
	
	@FindBy(id="btnLogin")
	WebElement btnLogin;

	private WebDriver driver;
	
	public NikolaLoginPage(WebDriver driver,String host) {
		this.driver = driver;
		driver.navigate().to(host);
		PageFactory.initElements(driver, this);
		
	}

	public NikolaHomePage successfulLogin(String user, String pass) throws Exception{
		userName.sendKeys(user);
		password.sendKeys(pass);
		btnLogin.click();
		return new NikolaHomePage();
	}
	public String failedLogin(String user, String pass) throws Exception{
		userName.sendKeys(user);
		password.sendKeys(pass);
		btnLogin.click();
		WebElement errorMsg = driver.findElement(By.id("lblLoginErrMsg"));
		return errorMsg.getText();
	}
	
}
